package cn.iocoder.yudao.module.engine.controller.app.audio;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.engine.controller.app.audio.vo.QueryAudioByKeywordReqVO;
import cn.iocoder.yudao.module.engine.controller.app.audio.vo.QueryAudioByTagReqVO;
import cn.iocoder.yudao.module.engine.controller.app.audio.vo.getKeywordListByTextReqVO;
import cn.iocoder.yudao.module.resource.api.IAudioServiceApi;
import cn.iocoder.yudao.module.resource.api.IKeywordServiceApi;
import cn.iocoder.yudao.module.resource.api.model.AudioDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "App -音频")
@RestController
@RequestMapping("/lm/audio")
@Validated
@Slf4j
public class AppAudioController {
    @Resource
    private IKeywordServiceApi keywordApi;
    @Resource
    private IAudioServiceApi audioApi;

    @PostMapping("/getKeywordListByText")
    @Operation(summary = "获取和此文本中匹配的关键字")
    public CommonResult<List<String>> getKeywordListByText(@Valid @RequestBody getKeywordListByTextReqVO req) throws Exception {
        final List<String> keywords = keywordApi.getKeywordListByText(req.getText());
        return success(keywords);
    }

    @PostMapping("/queryAudioByKeyword")
    @Operation(summary = "根据关键字查询音频，只要匹配到关键字就算")
    public CommonResult<List<AudioDTO>> queryAudioByKeyword(@Valid @RequestBody QueryAudioByKeywordReqVO req) throws Exception {
        final List<AudioDTO> audios = audioApi.queryAudioByKeyword(req.getRoleId(), req.getKeywords());
        return success(audios);
    }

    @PostMapping("/queryAudioByAllKeyword")
    @Operation(summary = "根据关键字查询音频，必须包括所有关键字")
    public CommonResult<List<AudioDTO>> queryAudioByAllKeyword(@Valid @RequestBody QueryAudioByKeywordReqVO req) throws Exception {
        final List<AudioDTO> audios = audioApi.queryAudioByAllKeyword(req.getRoleId(), req.getKeywords());
        return success(audios);
    }

    @PostMapping("/queryAudioByTag")
    @Operation(summary = "根据标签查询音频，只要匹配到标签就算")
    public CommonResult<List<AudioDTO>> queryAudioByTag(@Valid @RequestBody QueryAudioByTagReqVO req) throws Exception {
        final List<AudioDTO> audios = audioApi.queryAudioByTag(req.getRoleId(), req.getTags());
        return success(audios);
    }

    @PostMapping("/queryAudioByAllTag")
    @Operation(summary = "根据标签查询音频，必须被所有的标签标记")
    public CommonResult<List<AudioDTO>> queryAudioByAllTag(@Valid @RequestBody QueryAudioByTagReqVO req) throws Exception {
        final List<AudioDTO> audios = audioApi.queryAudioByAllTag(req.getRoleId(), req.getTags());
        return success(audios);
    }

}
